package com.spark.daoImpl;

import com.spark.dao.TaskDao;
import com.spark.pojo.Task;
import com.spark.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author jianger
 * @ date  2018/3/30-10:01
 * @project com.spark.daoImpl
 */
public class TaskDaoImpl implements TaskDao {

    /**
     * 根据主键查找task
     *
     * @param taskId
     * @return
     */
    @Override
    public Task findById(long taskId) throws SQLException {
        QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
        String sql = "select * from task where task_id=?";
        Task task = queryRunner.query(sql, new BeanHandler<Task>(Task.class), taskId);
        return task;

    }
}

















